//
//  TokenFooterView.swift
//  GhostWorld
//
//  Created by Kam on 2018/6/18.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit
import PKHUD

protocol TokenFooterViewDelegate {
  func purchase()
  func displayChargeInstruction()
  func displayChargeAgreement()
}

class TokenFooterView: UICollectionReusableView {
  
  // MARK: - IBOutlets
  
  @IBOutlet private weak var purchaseButton: UIButton!
  @IBOutlet private weak var agreeButton: UIButton!
  
  // MARK: - Private vars
  
  private var agree = true
  
  // MARK: - Private methods
  
  
  
  // MARK: - Public vars
  
  var delegate: TokenFooterViewDelegate?
  
  // MARK: - Lifecycle
  
  override func willMove(toSuperview newSuperview: UIView?) {
    super.willMove(toSuperview: newSuperview)
    
    purchaseButton.layer.cornerRadius = 4
  }
  
  // MARK: - IBActions
  
  @IBAction func agreeButtonTapped() {
    agree = !agree
    let imageName = agree ? "TokenChargeAgreeIcon" : "TokenChargeDisagreeIcon"
    agreeButton.setImage (
      UIImage(named: imageName),
      for: .normal
    )
    purchaseButton.isEnabled = agree
    purchaseButton.setTitleColor (
      UIColor(fromRGB: (agree ? 0xEDBF64 : 0x929292)),
      for: .normal
    )
  }
  
  @IBAction func purchase() {
    delegate?.purchase()
  }
  
  @IBAction func displayChargeInstruction() {
    delegate?.displayChargeInstruction()
  }
  
  @IBAction func displayChargeAgreement() {
    delegate?.displayChargeAgreement()
  }
  
  // MARK: - Public methods
  
  
}

extension TokenFooterView {
  static let defaultHeight: CGFloat = 260
}
